using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Web.Mvc;
using InfoTech.Core.Service;
using InfoTech.LanTranh.MucVu.Bussiness;

namespace InfoTech.LanTranh.MucVu.Service
{
    public class HIENTRANGHONNHANService : BaseService
    {
        public static bool Check_Insert_HIENTRANGHONNHAN(HIENTRANGHONNHAN hientranghonnhan)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &=
                dataContext.GetTable<HIENTRANGHONNHAN>().FirstOrDefault(
                    c => c.TENHIENTRANGHONNHAN.ToUpper() == hientranghonnhan.TENHIENTRANGHONNHAN.ToUpper()) == null;
            return result;
        }

        public static bool Check_Update_HIENTRANGHONNHAN(HIENTRANGHONNHAN hientranghonnhan)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &=
                dataContext.GetTable<HIENTRANGHONNHAN>().FirstOrDefault(
                    c => c.TENHIENTRANGHONNHAN.ToUpper() == hientranghonnhan.TENHIENTRANGHONNHAN.ToUpper() && c.MAHIENTRANGHONNHAN != hientranghonnhan.MAHIENTRANGHONNHAN) == null;
            return result;
        }

        public static bool Check_Delete_HIENTRANGHONNHAN(string[] strings)
        {
            bool result = true;
            DataContext dataContext = CreateDataContext();
            result &=
                dataContext.GetTable<SOHONNHAN>().FirstOrDefault(
                    c => strings.Contains(c.MAHIENTRANGHONNHAN + "")) == null;
            return result;
        }

        public static void Delete(HIENTRANGHONNHAN hientranghonnhan)
        {
        }

        public static IEnumerable<SelectListItem> Get_List()
        {
            List<SelectListItem> list = new List<SelectListItem>();
            list.AddRange(InfoTech.Core.Data.Receiver.TypeObject<HIENTRANGHONNHAN>.SelectMany().OrderBy(c => c.PRIORITY).Select(
                    c => new SelectListItem() { Text = c.TENHIENTRANGHONNHAN, Value = c.MAHIENTRANGHONNHAN + "" }));
            return list;
        }
    }
}
